var planet = [
    {id:0,name:'G1'},
    {id:1,name:'G2'},
    {id:2,name:'G3'},
    {id:3,name:'I7'},
    {id:4,name:'I9'},
    {id:5,name:'I10'},
    {id:6,name:'M11'},
    {id:7,name:'M12'},
    {id:8,name:'M13'},
    {id:9,name:'M14'},
    {id:10,name:'M15'},
    {id:11,name:'M16'},
    {id:12,name:'M17'},
    {id:13,name:'M18'},
    {id:14,name:'M21'},
    {id:15,name:'M22'},
    {id:16,name:'M23'},
    {id:17,name:'M24'},
    {id:18,name:'M25'},
    {id:19,name:'M26'},
    {id:20,name:'M27'},
    {id:21,name:'M28'},
    {id:22,name:'M31'},
    {id:23,name:'M32'},
    {id:24,name:'M33'},
    {id:25,name:'M34'},
    {id:26,name:'M35'},
    {id:27,name:'M36'},
    {id:28,name:'M37'},
    {id:29,name:'M38'}];
var xjleftChart3 = echarts.init(document.getElementById('left_chart3'),'macarons');
xjleftChart3.showLoading();
// getData();
getChartJson();
var dataArr;
function getChartJson() {
    $.getJSON('../../starConection.json', function (json) {
        xjleftChart3.hideLoading();
        dataArr = json.connetion;
        getData1(0);
        getTimeInterval(1);
    })
}
function getTimeInterval(index) {
    if(index>=dataArr.length){
        index = 0;
    }
    var pl = this.planet;
    var time = dataArr[index].time;
    setTimeout(function () {
        getData1(index);
        getTimeInterval(index+1)
    },time*1000);
}
function getData1(index) {
    xjleftChart3.clear();
    var starts = dataArr[index].starts,
        links = [],
        newStarts = [];
    for (var j = 0; j< starts.length;j++){
        var p = this.planet.filter(function (item,index) {
            return item.name === starts[j]
        });
        var tmp = {
            id: p[0].id,
            name: starts[j]
        };
        newStarts.push(tmp)
    }

    // console.log(111,newStarts);
    for (var i = 0; i< newStarts.length;i+=2){
        var item = {
            source: newStarts[i].id+'',
            target: newStarts[i+1].id+''
        };
        links.push(item)
    }

    // console.log(links);

    option = {
        title:{
            left:'center',
            textStyle:{
                color:'#fff',

            }
        },
        tooltip: {},
        legend: [{
            show:false
        }],

        animationDuration:500,
        animationEasing: 'ExponentialOut',
        grid:{
            x:0,   //左侧与y轴的距离
            y:0,   //top部与x轴的距离
            x2:0,   //右侧与y轴的距离
            y2:0    //bottom部与x轴的距离
        },
        color : ['#00ffff'],
        series : [
            {
                name: 'Les Miserables',
                type: 'graph',
                layout: 'circular',
                circular: {
                    rotateLabel: true
                },
                data: planet,
                links: links,
                // categories: categories,
                roam: true,
                label: {
                    normal: {
                        position: 'right',
                        formatter: '{b}',
                        color : '#fff',
                        textStyle:{
                            fontSize:30
                        }
                    },
                    emphasis : {//高亮状态
                        position: 'right',
                        formatter: '{b}',
                        textStyle : {
                            color : '#00ffff'
                        }
                    }
                },
                itemStyle : {
                    normal : {
                        label : {
                            show : true
                        },
                        borderType : 'solid',
                        borderWidth : 2,
                        opacity : 1,
                        color : '#00ffff'
                    },
                    emphasis : {
                        label : {
                            show : true
                        },
                        borderType : 'solid',
                        color : '#00ffff',
                        borderWidth : 2,
                        opacity : 1
                    }
                },
                lineStyle: {
                    normal: {
                        color: '#00ffff',
                        curveness: 0.3,
                        width:5
                    }
                }
            }
        ]
    };
    xjleftChart3.setOption(option);
    console.log(option);

}
function getData() {
    $.get('../../les-miserables.gexf', function (xml) {
        xjleftChart3.hideLoading();

        var graph = echarts.dataTool.gexf.parse(xml);
        //console.log(graph);
        var categories = [];
        for (var i = 0; i < 9; i++) {
            categories[i] = {
                name: '类目' + i
            };
        }

        // graph.nodes.forEach(function (node) {
        //     node.itemStyle.color=node.color;
        //
        //     node.value = node.symbolSize;
        //     node.symbolSize /= 1.5;
        //     node.label = {
        //         normal: {
        //             show: node.symbolSize > 5
        //         }
        //     };
        //     node.category = node.attributes.modularity_class;
        // });
        console.log("links",graph.links);
        console.log("nodes",graph.nodes);
        console.log("categories",categories)

        option = {
            title:{
                left:'center',
                textStyle:{
                    color:'#fff',

                }
            },
            tooltip: {},
            legend: [{
                show:false
            }],

            animationDuration:2000,
            animationEasing: 'ExponentialOut',
            grid:{
                x:0,   //左侧与y轴的距离
                y:0,   //top部与x轴的距离
                x2:0,   //右侧与y轴的距离
                y2:0    //bottom部与x轴的距离
            },
            color : ['#00ffff','#fff'],
            series : [
                {
                    name: 'Les Miserables',
                    type: 'graph',
                    layout: 'circular',
                    circular: {
                        rotateLabel: true
                    },
                    data: graph.nodes,
                    links: graph.links,
                    categories: categories,
                    roam: true,
                    label: {
                        normal: {
                            position: 'right',
                            formatter: '{b}',
                            color : '#fff',
                            textStyle:{
                                fontSize:30
                            }
                        },
                        emphasis : {//高亮状态
                            position: 'right',
                            formatter: '{b}',
                            textStyle : {
                                color : '#00ffff'
                            }
                        }
                    },
                    itemStyle : {
                        normal : {
                            label : {
                                show : true
                            },
                            borderType : 'solid',
                            borderWidth : 2,
                            opacity : 1,
                            color : '#00ffff'
                        },
                        emphasis : {
                            label : {
                                show : true
                            },
                            borderType : 'solid',
                            color : '#00ffff',
                            borderWidth : 2,
                            opacity : 1
                        }
                    },
                    lineStyle: {
                        normal: {
                            color: '#00ffff',
                            curveness: 0.3,
                            width:5
                        }
                    }
                }
            ]
        };
        xjleftChart3.setOption(option);
        console.log(option);
    }, 'xml');
}
